enhanced_image=imgaussfilt(gray_image);
% 计算水平和垂直梯度
[Gx, Gy] = imgradientxy(enhanced_image, 'sobel');

% 合成梯度强度
gradient_magnitude = sqrt(Gx.^2 + Gy.^2);
gradient_magnitude = uint8(gradient_magnitude * 255 / max(gradient_magnitude(:))); % 归一化到 [0, 255]
imhist(gradient_magnitude);

imshow(gradient_magnitude>40);

% 保存梯度图像
imwrite(gradient_magnitude, 'gradient_magnitude.png');
